//
//  MBGoodsIrregularitiesPopView.m
//  MemberBusiness-ios
//
//  Created by cherry pu on 2018/4/23.
//  Copyright © 2018年 zhangXin. All rights reserved.
//

#import "MBGoodsIrregularitiesPopView.h"

@interface MBGoodsIrregularitiesPopView()
@property (nonatomic,weak) UIView * backShadowView;
@property (nonatomic,weak) UIImageView * containView;

@end

@implementation MBGoodsIrregularitiesPopView

- (instancetype)init
{
    self = [super initWithFrame:[UIScreen mainScreen].bounds];
    if (self) {
        //创建shadowView
        UIView * backShadowView = [[UIView alloc] init];
        backShadowView.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.7];
        backShadowView.alpha = 0.0;
        [self addSubview:backShadowView];
        self.backShadowView = backShadowView;
        
        [backShadowView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(close)]];
        
        [backShadowView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self).insets(UIEdgeInsetsZero);
        }];
        
        UIImageView * containView = [[UIImageView alloc] initWithFrame:CGRectMake([UIView lf_sizeFromIphone6:45], SCREEN_HEIGHT, SCREEN_WIDTH-[UIView lf_sizeFromIphone6:90], [UIView lf_sizeFromIphone6:145])];
        containView.image = [UIImage imageFromColor:[UIColor whiteColor] forSize:CGSizeMake( SCREEN_WIDTH-[UIView lf_sizeFromIphone6:90], [UIView lf_sizeFromIphone6:145]) withCornerRadius:[UIView lf_sizeFromIphone6:6]];
        [self addSubview:containView];
        containView.userInteractionEnabled = YES;
        self.containView = containView;
        
        UILabel* messageLabel = [[UILabel alloc]init];
        messageLabel.text = @"违规信息";
        messageLabel.font = [UIFont lf_mediumFontOfSize:16];
        messageLabel.textColor = [UIColor colorWithR:30 G:30 B:30];
        [containView addSubview:messageLabel];
        
        [messageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(containView);
            make.top.equalTo(containView).offset([UIView lf_sizeFromIphone6:18]);
        }];

        
        UILabel* titleLabel = [[UILabel alloc]init];
        NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
        [paragraphStyle setLineSpacing:[UIView lf_sizeFromIphone6:3]];
        NSMutableAttributedString* attStr = [[NSMutableAttributedString alloc]initWithString:@"该商品不属于平台规定的销售范围，\n请修改后再提交" attributes:@{NSFontAttributeName:[UIFont lf_mediumFontOfSize:14],NSForegroundColorAttributeName:[UIColor colorWithR:120 G:120 B:120 A:0.5],NSParagraphStyleAttributeName:paragraphStyle}];
        titleLabel.attributedText = attStr;
        titleLabel.numberOfLines = 0;
        titleLabel.textAlignment = NSTextAlignmentCenter;
        [containView addSubview:titleLabel];
        
        [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(containView).offset([UIView lf_sizeFromIphone6:50]);
            make.left.equalTo(containView).offset([UIView lf_sizeFromIphone6:20]);
            make.right.equalTo(containView).offset([UIView lf_sizeFromIphone6:-20]);
        }];
        
        UIView* line = [[UIView alloc]init];
        line.backgroundColor = COLOR_LINE;
        [containView addSubview:line];
        
        [line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(containView).offset([UIView lf_sizeFromIphone6:-43]);
            make.left.equalTo(containView);
            make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH-[UIView lf_sizeFromIphone6:90], [UIView lf_sizeFromIphone6:1]));
        }];
        
        
        UIButton* cancelButton = [[UIButton alloc]init];
        [cancelButton addTarget:self action:@selector(close) forControlEvents:UIControlEventTouchUpInside];
        [cancelButton setTitle:@"知道了" forState:UIControlStateNormal];
        cancelButton.titleLabel.font = [UIFont lf_systemFontOfSize:16];
        [cancelButton setTitleColor:[UIColor colorWithR:255 G:99 B:0] forState:UIControlStateNormal];
        [containView addSubview:cancelButton];
        
        [cancelButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(line.mas_bottom);
            make.left.right.bottom.equalTo(containView);
        }];
        
    }
    return self;
}

- (void)show
{
    [[UIApplication sharedApplication].keyWindow addSubview:self];
    
    [UIView animateWithDuration:0.3 animations:^{
        self.backShadowView.alpha = 1.0;
        self.containView.y = (SCREEN_HEIGHT - self.containView.height)/2;
    }];
}

- (void)close
{
    [self endEditing:YES];
    [UIView animateWithDuration:0.3 animations:^{
        self.backShadowView.alpha = 0.0;
        self.containView.y = SCREEN_HEIGHT;
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
}

@end
